package com.topsoft.email.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.topsoft.email.service.IEmailSenderService;
import com.topsoft.email.util.bean.AjaxJson;
import com.topsoft.email.util.bean.MailParamBean;
import com.topsoft.email.util.enums.MailType;

@Controller
@RequestMapping("/mail")
public class MailSendAction {
	
	@Autowired
	IEmailSenderService emailSenderService;
	
	
	
	@RequestMapping(value = "/index.action",method={ RequestMethod.GET })
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response,Model model) throws Exception {
		
		return new ModelAndView("index");
	}
	
	
	@RequestMapping(value = "/sendJoddMail.action",method={ RequestMethod.GET })
	@ResponseBody
	public AjaxJson sendJoddMail(HttpServletRequest request, HttpServletResponse response,Model model,MailParamBean paramBean) throws Exception {
		
		paramBean.setMailUserId("1");
		paramBean.setReceiver("243860327@qq.com");
		paramBean.setTitle("你好吗");
		paramBean.setMailType(MailType.HTML);
		paramBean.setContent("<h1>你好吗</h1>");
		
		
		AjaxJson json =emailSenderService.sendJoddMail(paramBean);
		
		
		return json;
	}
	
	
	@RequestMapping(value = "/sendJavaMail.action",method={ RequestMethod.GET })
	@ResponseBody
	public AjaxJson sendJavaMail(HttpServletRequest request, HttpServletResponse response,Model model,MailParamBean paramBean) throws Exception {
		
		paramBean.setMailUserId("1");
		paramBean.setReceiver("243860327@qq.com");
		paramBean.setTitle("你好吗");
		paramBean.setMailType(MailType.HTML);
		paramBean.setContent("<h1>你好吗</h1>");
		
		
		AjaxJson json =emailSenderService.sendJavaMail(paramBean);
		
		
		return json;
	}
	
	
	@RequestMapping(value = "/sendCloudMail.action",method={ RequestMethod.GET })
	@ResponseBody
	public AjaxJson sendCloudMail(HttpServletRequest request, HttpServletResponse response,Model model,MailParamBean paramBean) throws Exception {
		
		paramBean.setMailUserId("2");
		paramBean.setReceiver("243860327@qq.com");
		paramBean.setTitle("你好吗");
		paramBean.setMailType(MailType.HTML);
		paramBean.setContent("<h1>你好吗</h1>");
		
		
		AjaxJson json =emailSenderService.sendCloudMail(paramBean);
		return json;
	}

}
